package cn.hdu.liang.ch04;

import net.jcip.annotations.ThreadSafe;

import java.util.Vector;

/**
 * 扩展Vector并增加一个 put-if-absent 方法
 */
@ThreadSafe
public class BetterVector<E> extends Vector<E> {
    // 扩展一个serializable class，你必须重新定义 serialVersionUID
    static final long serialVersionUID = -3963416950630760754L;

    public synchronized boolean putIfAbsent(E x) {
        boolean absent = !contains(x);
        if(absent) {
            add(x);
        }
        return absent;
    }
}
